package my.Interceptor.log1;



import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * 根据注解值拦截
 * @author xsw
 * @date 2017-10-25
 */
@Aspect
@Component
public class LogAdvice {

    @Pointcut("@annotation(my.Interceptor.log1.Log)")
    private void advice() {}

    @Before("advice()")
    public void doBefore(JoinPoint jp) {
        Signature signature = jp.getSignature();    
        MethodSignature methodSignature = (MethodSignature)signature;    
        Method targetMethod = methodSignature.getMethod();    
        Log log = targetMethod.getAnnotation(Log.class);
        String value = log.value();
        System.out.println("获取到注解值："+value);
        String methodInfo = jp.getSignature().getName();;
        System.out.println("获取到："+methodInfo);
    }
    @Before("advice()")
    public void doBefore_01(JoinPoint point) {
    	//获取类上的Log注解
    	Log log = point.getTarget().getClass().getAnnotation(Log.class);
    	//获取方法上的Log注解
    	Signature signature = point.getSignature();    
    	MethodSignature methodSignature = (MethodSignature)signature;    
    	Method targetMethod = methodSignature.getMethod();
    	Log log_ = targetMethod.getAnnotation(Log.class);
    	
    }
}
